package com.library.bookmanagement.controller;

import com.library.bookmanagement.service.BookService;
import com.library.bookmanagement.util.Constant;
import com.library.bookmanagement.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author ：ZXM
 * @date ：Created in 2020/5/26 16:29
 * @description：书籍控制类
 */
@CrossOrigin(origins = "*",maxAge = 3600)
@RestController
@ResponseBody
@RequestMapping("/books")
@Api(value = "BookController",tags = {"图书控制接口"})
public class BookController {
    @Autowired
    private BookService bookService;

    /**
    * @Description: 显示所有图书信息，填充首页内容
    * @Param: [pageNum]
    * @return: com.library.bookmanagement.util.ResultUtil<java.util.Map<java.lang.String,java.lang.Object>>
    * @Author: ZXM
    * @Date: 2020/6/10
    */
    @ApiOperation("显示所有图书信息")
    @GetMapping("/bookList")
    public ResultUtil<Map<String,Object>> bookList(
            @ApiParam(value = "第几页",name = "pageNum")
            @RequestParam(name = "pageNum") Integer pageNum
            ){
        return bookService.getBooksList(pageNum, Constant.pageSize);
    }

    /**
    * @Description: 按照图书类型分类显示
    * @Param: [pageNum, bookType]
    * @return: com.library.bookmanagement.util.ResultUtil<java.util.Map<java.lang.String,java.lang.Object>>
    * @Author: ZXM
    * @Date: 2020/6/10
    */
    @ApiOperation(value = "按照图书类型分类显示")
    @GetMapping("/bookTypekList")
    public ResultUtil<Map<String,Object>> bookTypeList(
            @ApiParam(value = "第几页",name = "pageNum")
            @RequestParam(name = "pageNum") Integer pageNum,
            @ApiParam(value = "书籍类型",name = "bookType")
            @RequestParam(name = "bookType") String bookType
    ){
        return bookService.getBookTypeList(pageNum,Constant.pageSize,bookType);
    }

    /**
    * @Description: 按照图书类型和图书名称进行查询,满足级联查询
    * @Param: [pageNum, bookName, bookType]
    * @return: com.library.bookmanagement.util.ResultUtil<java.util.Map<java.lang.String,java.lang.Object>>
    * @Author: ZXM
    * @Date: 2020/6/10
    */
    @ApiOperation(value = "按照图书类型和图书名称进行查询")
    @GetMapping("/queryBook")
    public ResultUtil<Map<String,Object>> queryBook(
            @ApiParam(value = "书籍名称关键字",name = "bookName")
            @RequestParam(name = "bookName") String bookName,
            @ApiParam(value = "书籍类型",name = "bookType")
            @RequestParam(name = "bookType") String bookType
    ){
        return bookService.queryBookByTypeAndName(bookName,bookType);
    }
}
